import pandas as pd
df=pd.read_excel("某店铺2023年1—9月份评价数据.xlsx")
for i in range(len(df['日期'])):
    date=df['日期'].iloc[i]
    if isinstance(date,str):
        df.loc[i,'日期']=date.split('更新于')[1]
df['日期']=pd.to_datetime(df['日期']).dt.date
print(df)

import pandas as pd
df = pd.read_excel('某店铺2023年1—9月份评价数据.xlsx')
for i in range(len(df['日期'])):
    date = df['日期'].iloc[i]
    if isinstance(date, str):
        df.loc[i, '日期'] = date.split('更新于')[1]
df['日期'] = pd.to_datetime(df['日期']).dt.date
print(df)
print('处理重复值前数据的行数: ', len(df))
df.drop_duplicates(subset=['评价'], inplace=True, ignore_index=True)
print('处理重复值后数据的行数: ', len(df))
df.to_excel('某店铺2023年1—9月份评价数据_预处理.xlsx', index=False)

#散点图
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df=pd.read_excel('店铺数据新表.xlsx')
df1=df.groupby('均价（元/人）').sum(numeric_only=True)
plt.figure(figsize=(8,5))
sns.set_style(style='darkgrid',rc={'font.sans-serif':'SimHei'})
sns.set_palette('bright')
sns.scatterplot(x=df1.index,y=df1['评价数'])
plt.title('散点图')
plt.show()

#日历图
import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Calendar
from pyecharts.globals import ThemeType
df = pd.read_excel('某店铺2023年1—9月份评价数据_预处理.xlsx')
df1 = df.groupby('日期').count()
max = max(df1['评价'])
min = min(df1['评价'])
data = [list(z) for z in zip(df1.index, df1['评价'])]
calendar = Calendar(init_opts=opts.InitOpts(
    width='850px', height='300px',
    theme=ThemeType.ESSOS, page_title='日历图'))
calendar.add(series_name='', yaxis_data=data,
    calendar_opts=opts.CalendarOpts(
    range_=['2023-01-01','2023-9-30'])
)
calendar.set_global_opts(
    title_opts=opts.TitleOpts(
        title='某店铺2023年1—9月份每日评价数日历图',
        pos_left='center'),
    legend_opts=opts.LegendOpts(is_show=False),
    visualmap_opts=opts.VisualMapOpts(
        orient='horizontal',
        max_=max,
        min_=min,
        pos_top='75%',
        pos_left='center'
    )
)
calendar.render('calendar.html')

#词云图
import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import WordCloud
import jieba
df = pd.read_excel('某店铺2023年1—9月份评价数据_预处理.xlsx')
content = ''
for text in df['评价']:
    content = content + text
words=jieba.lcut(content)
word_counts= {}
for word in words:
    if len(word) > 1:
        word_counts[word]=word_counts.get(word, 0) + 1
wordCloud=WordCloud(init_opts=opts.InitOpts(page_title='词云图'))
wordCloud.add(series_name='', data_pair=word_counts.items(),
    word_size_range=[20, 80])
wordCloud.set_global_opts(
    title_opts=opts.TitleOpts(
        title='某店铺2023年1—9月份评价词云图',pos_left='center'),
    legend_opts=opts.LegendOpts(is_show=False)
)
wordCloud.render('wordCloud.html')